<!-- 表单 》 多选框 -->

<template>
  <el-form-item v-bind="formItem" :class="`${formItem.class}${hasAll ? ` ${className}-hasAll` : ''}`">
    <!-- 隐藏输入框，触发校验 -->
    <el-input v-show="false" :value="model.join()" />

    <!-- 标签 -->
    <template v-if="hasLabelSlot" #label>
      <slot name="label" :label="formItem.label">{{ formItem.label }}</slot>
    </template>

    <div v-if="hasAll" :class="`CoreWeb-Checkbox${isBtn ? 'Btn' : ''}All`">
      <el-checkbox-button v-if="isBtn" v-model="isAll" v-bind="allProps" @change="changeAll" />
      <el-checkbox v-else v-model="isAll" v-bind="allProps" @change="changeAll" />
    </div>

    <el-checkbox-group
      v-if="isBtn"
      v-model="model"
      v-bind="commonProps"
      :class="`${className} CoreWeb-CheckboxBtnGroup`"
      @change="emitChange"
    >
      <el-checkbox-button
        v-for="(item, i) in selectData"
        :key="`${item[0]}-${i}`"
        :class="getHideClass(item)"
        :label="item[0]"
        :disabled="getDisabled(item)"
      >
        <span class="CoreWeb-checkbox-btn">
          <slot name="item" :item="item">
            <span>{{ item[1] }}</span>
            <span v-if="showRight" class="CoreWeb-checkbox-btn-right">{{ item[rightIndex] }}</span>
          </slot>
        </span>
      </el-checkbox-button>
    </el-checkbox-group>

    <el-checkbox-group
      v-else
      v-model="model"
      v-bind="commonProps"
      :class="`${className} CoreWeb-CheckboxGroup`"
      @change="emitChange"
    >
      <el-checkbox
        v-for="(item, i) in selectData"
        :key="`${item[0]}-${i}`"
        :class="getHideClass(item)"
        :label="item[0]"
        :disabled="getDisabled(item)"
      >
        <span class="CoreWeb-checkbox">
          <slot name="item" :item="item">
            <span>{{ item[1] }}</span>
            <span v-if="showRight" class="CoreWeb-checkbox-right">{{ item[rightIndex] }}</span>
          </slot>
        </span>
      </el-checkbox>
    </el-checkbox-group>
  </el-form-item>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import mixForm from '../mixForm'
import FormSelectMulti from '../FormSelectMulti'

const name = 'FormCheckbox'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name,

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [mixForm],

  /**
   * 属性注册 (抽取以便查阅)
   */
  props: CORE.WEB[name],

  /**
   * 状态数据 (函数返回对象)
   */
  data() {
    return FormSelectMulti.data()
  },

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: FormSelectMulti.computed,

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: FormSelectMulti.methods,
}
</script>
